package genosAgape.ui.menuPrincipal;

import genosAgape.ui.Arvore;
import genosAgape.ui.MdiGA;
import genosAgape.ui.die.Cadastrar;
import genosAgape.ui.die.Pesquisar;
import genosAgape.ui.die.Pontuar;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.text.ParseException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

public class Dies extends JPanel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JButton btnCadstrar;
	private JButton btnEditar;
	private JButton btnPontuar;
	private JButton btnNavegar;
	
	public Dies() {
		
		setLayout(null);
		setOpaque(false);
		
		JPanel painel = new JPanel();
		painel.setOpaque(false);
		painel.setBounds(5, 5, 303, 277);
		painel.setBorder(null);
		painel.setLayout(null);
		painel.setBackground(Color.WHITE);
		add(painel);
		
		btnCadstrar = new JButton("Casdastrar");
		btnEditar = new JButton("Editar");
		btnPontuar = new JButton("Pontuar");		
		btnNavegar = new JButton("Navegar");		
		
		btnCadstrar.setOpaque(true);
				
		btnCadstrar.setBounds(10, 11, 137, 122);
		btnCadstrar.setIcon(new ImageIcon(Dies.class.getResource("/genosAgape/ui/img/icons/addDie.png")));
		
		btnEditar.setBounds(157, 11, 137, 122);
		btnEditar.setIcon(new ImageIcon(Dies.class.getResource("/genosAgape/ui/img/icons/editDie.png")));
		
		btnPontuar.setBounds(10, 144, 137, 122);
		btnPontuar.setIcon(new ImageIcon(Dies.class.getResource("/genosAgape/ui/img/icons/dollar.png")));
		
		btnNavegar.setBounds(157, 144, 137, 122);
		btnNavegar.setIcon(new ImageIcon(Dies.class.getResource("/genosAgape/ui/img/icons/arvore.png")));
		
		painel.add(btnCadstrar);
		painel.add(btnEditar);
		painel.add(btnPontuar);
		painel.add(btnNavegar);
		
		addListener();
	}
	private void addListener(){
		btnCadstrar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Cadastrar cd;
				try {
					cd = Cadastrar.getInstance();					
					if(cd.getParent()!=MdiGA.areaTrabalho) MdiGA.areaTrabalho.add(cd);
					cd.setSelected(true);
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (PropertyVetoException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} 				
			}
		});
		btnEditar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
					try {
						Pesquisar ps = Pesquisar.getInstance();
						if(ps.getParent()!=MdiGA.areaTrabalho) MdiGA.areaTrabalho.add(ps);
						ps.setSelected(true);
					} catch (PropertyVetoException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					} catch (ParseException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
			}
		});
		btnPontuar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					Pontuar pt = Pontuar.getInstance();
					if(pt.getParent()!=MdiGA.areaTrabalho) MdiGA.areaTrabalho.add(pt);
					pt.setSelected(true);
				} catch (PropertyVetoException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
			}
		});
		btnNavegar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
				Arvore av = Arvore.getInstance();
				if(av.getParent()!=MdiGA.areaTrabalho) MdiGA.areaTrabalho.add(av);				
					av.setSelected(true);
				} catch (PropertyVetoException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
	}
}
